package com.maybach.core.ao.impl;

import com.maybach.common.enums.AttachBizTypeEnum;
import com.maybach.common.enums.FlowBizTypeEnun;
import com.maybach.common.model.PartnerDO;
import com.maybach.common.model.UserDO;
import com.maybach.common.po.EnterpriseCertificatePO;
import com.maybach.common.po.PersonCertificatePO;
import com.maybach.common.po.ProviderCertificatePO;
import com.maybach.component.city.CityData;
import com.maybach.component.city.domain.City;
import com.maybach.core.ao.CertificateAO;
import com.maybach.core.ao.FlowApplyAO;
import com.maybach.core.form.partner.PartnerQueryForm;
import com.maybach.core.form.user.UserQueryForm;
import com.maybach.core.manager.PartnerManager;
import com.maybach.core.manager.UserManager;
import com.maybach.dubbo.api.BizResult;
import com.maybach.dubbo.api.enums.AuditStatusEnum;
import com.maybach.dubbo.api.model.EnterpriseCertificateModel;
import com.maybach.dubbo.api.model.PersonCertificateModel;
import com.maybach.dubbo.api.model.ProviderCertificateModel;
import com.maybach.util.AssertUtil;
import com.maybach.util.ImgUrlUtil;
import com.maybach.util.query.support.PageResult;
import com.maybach.workflow.common.api.enums.FlowStateEnum;
import com.maybach.workflow.common.model.FlowApplyDO;
import com.maybach.workflow.common.query.FlowApplyIndexQuery;
import com.maybach.workflow.common.query.FlowApplyQuery;
import com.maybach.workflow.core.manager.FlowApplyManager;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by houenxun on 16/1/28.
 */
@Component
public class CertificateAOImpl implements CertificateAO {

    Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    protected FlowApplyAO flowApplyAO;
    @Autowired
    protected UserManager userManager;
    @Autowired
    protected PartnerManager partnerManager;
    @Autowired
    protected FlowApplyManager flowApplyManager;

    @Override
    public PageResult<FlowApplyDO> queryPersonCertificate(UserQueryForm userQueryForm) {
        FlowApplyQuery flowApplyQuery = new FlowApplyQuery();
        flowApplyQuery.setPageSize(userQueryForm.getPageSize());
        flowApplyQuery.setPageNo(userQueryForm.getPageNo());
        FlowApplyQuery.Criteria c = flowApplyQuery.or();
        c.andFlowBizTypeIn(Arrays.asList(FlowBizTypeEnun.personalCertificate.name()));
        if (CollectionUtils.isNotEmpty(userQueryForm.getStatus())) {
            c.andStateIn(userQueryForm.getStatus());
        }
        List<FlowApplyIndexQuery> list = new ArrayList<FlowApplyIndexQuery>();
        if (StringUtils.isNotBlank(userQueryForm.getCorpName())) {
            list.add(this.createIndexLikeQuery("corpName", userQueryForm.getCorpName()));
        }

        if (StringUtils.isNotBlank(userQueryForm.getLoginName())) {
            list.add(this.createIndexLikeQuery("loginName", userQueryForm.getLoginName()));
        }

        if (StringUtils.isNotBlank(userQueryForm.getRealName())) {
            list.add(this.createIndexLikeQuery("realName", userQueryForm.getRealName()));
        }

        return flowApplyAO.queryFlowApply(flowApplyQuery, list);
    }


    @Override
    public PageResult<FlowApplyDO> queryEnterpriseCertificate(PartnerQueryForm partnerQueryForm) {

        return queryPartnerCertificate(partnerQueryForm, FlowBizTypeEnun.enterpriseCertificate.name());
    }

    private PageResult<FlowApplyDO> queryPartnerCertificate(PartnerQueryForm partnerQueryForm, String flowBizType) {
        FlowApplyQuery flowApplyQuery = new FlowApplyQuery();
        flowApplyQuery.setPageSize(partnerQueryForm.getPageSize());
        flowApplyQuery.setPageNo(partnerQueryForm.getPageNo());
        FlowApplyQuery.Criteria c = flowApplyQuery.or();
        c.andFlowBizTypeIn(Arrays.asList(flowBizType));
        if (CollectionUtils.isNotEmpty(partnerQueryForm.getStatus())) {
            c.andStateIn(partnerQueryForm.getStatus());
        }
        List<FlowApplyIndexQuery> list = new ArrayList<FlowApplyIndexQuery>();
        if (StringUtils.isNotBlank(partnerQueryForm.getCorpName())) {
            list.add(this.createIndexLikeQuery("corpName", partnerQueryForm.getCorpName()));
        }

        if (StringUtils.isNotBlank(partnerQueryForm.getContactsName())) {

            list.add(this.createIndexLikeQuery("contactsName", partnerQueryForm.getContactsName()));
        }

        if (StringUtils.isNotBlank(partnerQueryForm.getContactsPhone())) {
            list.add(this.createIndexLikeQuery("contactsPhone", partnerQueryForm.getContactsPhone()));
        }
        return flowApplyAO.queryFlowApply(flowApplyQuery, list);
    }

    private FlowApplyIndexQuery createIndexLikeQuery(String key, String value) {
        FlowApplyIndexQuery query = new FlowApplyIndexQuery();
        FlowApplyIndexQuery.Criteria criteria = query.or();
        criteria.andNameEqualTo(key);
        criteria.andValueLike("%" + value + "%");
        return query;
    }


    @Override
    public PageResult<FlowApplyDO> queryProviderCertificate(PartnerQueryForm partnerQueryForm) {
        return queryPartnerCertificate(partnerQueryForm, FlowBizTypeEnun.providerCertificate.name());
    }

    @Override
    public PersonCertificateModel queryPersonCertificateByUserId(Long userId) {
        FlowApplyQuery query = new FlowApplyQuery();
        query.setPageNo(query.DEFAULT_PAGE);
        query.setPageSize(query.DEFAULT_PAGE_SIZE);
        FlowApplyQuery.Criteria criteria = query.or();
        criteria.andAttachBizIdEqualTo(userId);
        criteria.andFlowBizTypeEqualTo(FlowBizTypeEnun.personalCertificate.name());

        PageResult<FlowApplyDO> pageResult = flowApplyAO.queryFlowApply(query, null);
        if (CollectionUtils.isEmpty(pageResult.getResult())) {
            return null;
        }

        if (pageResult.getResult().size() > 1) {
            throw new RuntimeException("数据重复");
        }
        FlowApplyDO flowApplyDO = pageResult.getResult().get(0);
        return this.assemblyModel((PersonCertificatePO) flowApplyDO.getContentObject(), flowApplyDO);
    }


    @Override
    public EnterpriseCertificateModel queryEnterpriseCertificateByUserId(Long userId) {
        UserDO userDO = userManager.selectByPrimaryKey(userId);

        if(null != userDO && userDO.getPartnerId() != null && userDO.getPartnerId() > 0){
            PartnerDO partnerDO = partnerManager.selectByPrimaryKey(userDO.getPartnerId());
            if(null != partnerDO){
                return this.asssembly(userDO, partnerDO);
            }
        }

        FlowApplyQuery query = new FlowApplyQuery();
        query.setPageNo(query.DEFAULT_PAGE);
        query.setPageSize(query.DEFAULT_PAGE_SIZE);
        FlowApplyQuery.Criteria criteria = query.or();
        criteria.andAttachBizIdEqualTo(userId);
        criteria.andFlowBizTypeEqualTo(FlowBizTypeEnun.enterpriseCertificate.name());

        PageResult<FlowApplyDO> pageResult = flowApplyAO.queryFlowApply(query, null);
        if (CollectionUtils.isEmpty(pageResult.getResult())) {
            return null;
        }

        if (pageResult.getResult().size() > 1) {
            throw new RuntimeException("数据重复");
        }
        FlowApplyDO flowApplyDO = pageResult.getResult().get(0);
        return this.assemblyModel((EnterpriseCertificatePO) flowApplyDO.getContentObject(), flowApplyDO);
    }

    EnterpriseCertificateModel asssembly(UserDO userDO,PartnerDO partnerDO){
        EnterpriseCertificateModel enterpriseCertificateModel = new EnterpriseCertificateModel();
        enterpriseCertificateModel.setUserId(userDO.getId());
        enterpriseCertificateModel.setCertificateCode(partnerDO.getCertificateCode());
        enterpriseCertificateModel.setCity(null == partnerDO.getCityId() ? null : String.valueOf(partnerDO.getCityId()));
        enterpriseCertificateModel.setProvince(null == partnerDO.getProviceId() ? null : String.valueOf(partnerDO.getProviceId()));

        enterpriseCertificateModel.setCityName(partnerDO.getCityName());
        enterpriseCertificateModel.setCorpName(partnerDO.getCorpName());
        enterpriseCertificateModel.setCredentialsImgs(ImgUrlUtil.parseList(partnerDO.getCredentialsImgs()));
        enterpriseCertificateModel.setLegalImgs(ImgUrlUtil.parseList(partnerDO.getLegalCertImgs()));
        enterpriseCertificateModel.setStoreImgs(ImgUrlUtil.parseList(partnerDO.getStoreImgs()));
        enterpriseCertificateModel.setApplyId(null);
        enterpriseCertificateModel.setStatus(partnerDO.getIsVerify());
        enterpriseCertificateModel.setMemo(partnerDO.getMemo());
        return enterpriseCertificateModel;
    }



    @Override
    public ProviderCertificateModel queryProviderCertificateByUserId(Long userId) {
        UserDO userDO = userManager.selectByPrimaryKey(userId);
        AssertUtil.notNull(userDO, "userDO by userId=" + userId);
        if(null == userDO.getPartnerId()){
            return null;
        }
        //.notNull(userDO.getPartnerId(), "userDO.getPartnerId() by userId=" + userId);
        FlowApplyQuery query = new FlowApplyQuery();
        query.setPageNo(query.DEFAULT_PAGE);
        query.setPageSize(query.DEFAULT_PAGE_SIZE);
        FlowApplyQuery.Criteria criteria = query.or();
        criteria.andAttachBizIdEqualTo(userDO.getPartnerId());
        criteria.andFlowBizTypeEqualTo(FlowBizTypeEnun.providerCertificate.name());

        PageResult<FlowApplyDO> pageResult = flowApplyAO.queryFlowApply(query, null);
        if (CollectionUtils.isEmpty(pageResult.getResult())) {
            return null;
        }

        if (pageResult.getResult().size() > 1) {
            throw new RuntimeException("数据重复");
        }
        FlowApplyDO flowApplyDO = pageResult.getResult().get(0);
        return this.assemblyModel((ProviderCertificatePO) flowApplyDO.getContentObject(), flowApplyDO);
    }


    ProviderCertificateModel assemblyModel(ProviderCertificatePO certificatePO, FlowApplyDO flowApplyDO) {
        ProviderCertificateModel providerCertificateModel = new ProviderCertificateModel();
        providerCertificateModel.setUserId(certificatePO.getUserId());
        providerCertificateModel.setApplyId(flowApplyDO.getId());
        providerCertificateModel.setStatus(this.getModelStatue(flowApplyDO.getState()));
        providerCertificateModel.setMemo(certificatePO.getMemo());
        return providerCertificateModel;
    }

    PersonCertificateModel assemblyModel(PersonCertificatePO certificatePO, FlowApplyDO flowApplyDO) {
        PersonCertificateModel personCertificateModel = new PersonCertificateModel();
        personCertificateModel.setUserId(certificatePO.getUserId());
        personCertificateModel.setCertImgs(certificatePO.getCertImgs());
        personCertificateModel.setCertNo(certificatePO.getCertNo());
        personCertificateModel.setRealName(certificatePO.getRealName());
        personCertificateModel.setVisitingCardImgs(certificatePO.getVisitingCardImgs());
        personCertificateModel.setApplyId(flowApplyDO.getId());
        personCertificateModel.setStatus(this.getModelStatue(flowApplyDO.getState()));
        personCertificateModel.setMemo(certificatePO.getMemo());
        return personCertificateModel;
    }


    EnterpriseCertificateModel assemblyModel(EnterpriseCertificatePO certificatePO, FlowApplyDO flowApplyDO) {
        EnterpriseCertificateModel enterpriseCertificateModel = new EnterpriseCertificateModel();
        enterpriseCertificateModel.setUserId(certificatePO.getUserId());
        enterpriseCertificateModel.setCertificateCode(certificatePO.getCertificateCode());
        enterpriseCertificateModel.setCity(null == certificatePO.getCity() ? null : String.valueOf(certificatePO.getCity()));
        enterpriseCertificateModel.setProvince(null == certificatePO.getProvince() ? null : String.valueOf(certificatePO.getProvince()));

        enterpriseCertificateModel.setCityName(certificatePO.getCityName());
        enterpriseCertificateModel.setCorpName(certificatePO.getCorpName());
        enterpriseCertificateModel.setCredentialsImgs(certificatePO.getCredentialsImgs());
        enterpriseCertificateModel.setLegalImgs(certificatePO.getLegalImgs());
        enterpriseCertificateModel.setStoreImgs(certificatePO.getStoreImgs());
        enterpriseCertificateModel.setApplyId(flowApplyDO.getId());
        enterpriseCertificateModel.setStatus(this.getModelStatue(flowApplyDO.getState()));
        enterpriseCertificateModel.setMemo(certificatePO.getMemo());
        return enterpriseCertificateModel;
    }

    private int getModelStatue(int flowState) {
        FlowStateEnum flowStateEnum = FlowStateEnum.getFlowState(flowState);
        if (flowStateEnum == FlowStateEnum.init || flowStateEnum == FlowStateEnum.cancle) {
            return AuditStatusEnum.init.getStatus();
        } else if (flowStateEnum == FlowStateEnum.end) {
            return AuditStatusEnum.end.getStatus();
        } else if (flowStateEnum == FlowStateEnum.reject) {
            return AuditStatusEnum.reject.getStatus();
        } else { // (flowStateEnum == FlowStateEnum.close)
            return AuditStatusEnum.end.getStatus();
        }
    }


    /**
     * 提交企业资料审核
     *
     * @param certificateModel
     * @return
     */
    @Override
    public BizResult submitEnterpriseApprove(EnterpriseCertificateModel certificateModel) {
        BizResult result = new BizResult();
        try {
            UserDO userDO = userManager.selectByPrimaryKey(certificateModel.getUserId());
            if (null == userDO) {
                result.setMsg("用户不存在");
                logger.error("用户不存在 userId={}", certificateModel.getUserId());
                return result;
            }
            if (userDO.getPartnerId() != null && userDO.getPartnerId() > 0) {
                result.setMsg("当前用户已申请");
                logger.error("当前用户存在多个活动的申请[person={}]", certificateModel);
                return result;
            }

            FlowApplyQuery query = new FlowApplyQuery();
            FlowApplyQuery.Criteria criteria = query.or();
            criteria.andAttachBizIdEqualTo(certificateModel.getUserId());
            criteria.andFlowBizTypeEqualTo(FlowBizTypeEnun.enterpriseCertificate.name());
            criteria.andStateIn(Arrays.asList(FlowStateEnum.init.getStatus(), FlowStateEnum.reject.getStatus(), FlowStateEnum.cancle.getStatus()));
            PageResult<FlowApplyDO> pageResult = flowApplyAO.queryFlowApply(query, null);
            if (pageResult.getTotalCount() > 1) {
                logger.error("当前用户存在多个活动的申请[person={}]", certificateModel);
                result.setMsg("当前用户存在多个活动的申请");
                return result;
            } else if (pageResult.getTotalCount() == 1) { // 更新操作
                FlowApplyDO applyDO = pageResult.getResult().get(0);
                if (applyDO.getState() == FlowStateEnum.init.getStatus()) {
                    result.setMsg("当前用户已申请");
                    logger.error("当前用户存在多个活动的申请[person={}]", certificateModel);
                    return result;
                } else {
                    EnterpriseCertificatePO enterpriseCertificatePO = this.assemblyPO(certificateModel, userDO);
                    applyDO.setContentObject(enterpriseCertificatePO);
                    flowApplyAO.reApplyFlow(applyDO, null);
                }
            } else { // 插入操作
                EnterpriseCertificatePO enterpriseCertificatePO = this.assemblyPO(certificateModel, userDO);
                FlowApplyDO flowApplyDO = new FlowApplyDO();
                flowApplyDO.setContentObject(enterpriseCertificatePO);
                flowApplyDO.setAttachBizId(certificateModel.getUserId());
                flowApplyDO.setAttachBizType(AttachBizTypeEnum.user.name());
                flowApplyDO.setFlowBizType(FlowBizTypeEnun.enterpriseCertificate.name());
                flowApplyAO.createApply(flowApplyDO);
            }

        } catch (Exception e) {
            logger.error("userId=" + certificateModel.getUserId(), e);
            result.setMsg("系统异常");
        }

        return result;
    }

    /**
     * 提交个人资料审核
     *
     * @param certificateModel
     * @return
     */
    @Override
    public BizResult submitPersionApprove(PersonCertificateModel certificateModel) {
        BizResult result = new BizResult();

        try {
            UserDO userDO = userManager.selectByPrimaryKey(certificateModel.getUserId());
            if (null == userDO) {
                result.setMsg("用户不存在");
                logger.error("用户不存在[person={}]", certificateModel);
                return result;
            }

            FlowApplyQuery query = new FlowApplyQuery();
            FlowApplyQuery.Criteria criteria = query.or();
            criteria.andAttachBizIdEqualTo(certificateModel.getUserId());
            criteria.andFlowBizTypeEqualTo(FlowBizTypeEnun.personalCertificate.name());
            criteria.andStateIn(Arrays.asList(FlowStateEnum.init.getStatus(), FlowStateEnum.reject.getStatus(), FlowStateEnum.cancle.getStatus()));
            PageResult<FlowApplyDO> pageResult = flowApplyAO.queryFlowApply(query, null);
            if (pageResult.getTotalCount() > 1) {
                logger.error("当前用户存在多个活动的申请[person={}]", certificateModel);
                result.setMsg("存在多个申请");
                return result;
            } else if (pageResult.getTotalCount() == 1) { // 更新操作
                FlowApplyDO applyDO = pageResult.getResult().get(0);
                if (applyDO.getState() == FlowStateEnum.init.getStatus()) {
                    logger.error("当前用户已申请[person={}]", certificateModel);
                    result.setMsg("当前用户已申请");
                } else {
                    PersonCertificatePO personCertificatePO = this.assemblyPO(certificateModel, userDO);
                    applyDO.setContentObject(personCertificatePO);
                    flowApplyAO.reApplyFlow(applyDO, null);
                }
            } else { // 插入操作
                PersonCertificatePO personCertificatePO = this.assemblyPO(certificateModel, userDO);
                FlowApplyDO flowApplyDO = new FlowApplyDO();
                flowApplyDO.setContentObject(personCertificatePO);
                flowApplyDO.setAttachBizId(certificateModel.getUserId());
                flowApplyDO.setAttachBizType(AttachBizTypeEnum.user.name());
                flowApplyDO.setFlowBizType(FlowBizTypeEnun.personalCertificate.name());
                flowApplyAO.createApply(flowApplyDO);
            }
            //userDO.setIsVerify(1);
            userManager.updateByPrimaryKeySelective(userDO);
        } catch (Exception e) {
            logger.error("userId=" + certificateModel.getUserId(), e);
            result.setMsg("系统异常");
        }
        return result;
    }


    @Override
    public BizResult submitProviderApprove(Long userId) {
        BizResult result = new BizResult();

        try {
            UserDO userDO = userManager.selectByPrimaryKey(userId);
            if (null == userDO) {
                result.setMsg("用户不存在");
                logger.error("用户不存在 userId={}", userId);
                return result;
            }
            /**
             * 还未进行企业资格认证不能成功供应商
             */
            if (userDO.getPartnerId() == null) {
                result.setMsg("用户对应的商家不存在");
                logger.error("商家不存在 userId={}", userId);
                return result;
            }

            PartnerDO partnerDO = partnerManager.selectByPrimaryKey(userDO.getPartnerId());


            FlowApplyQuery query = new FlowApplyQuery();
            FlowApplyQuery.Criteria criteria = query.or();
            criteria.andAttachBizIdEqualTo(partnerDO.getId());
            criteria.andFlowBizTypeEqualTo(FlowBizTypeEnun.providerCertificate.name());
            criteria.andStateIn(Arrays.asList(FlowStateEnum.init.getStatus(), FlowStateEnum.reject.getStatus(), FlowStateEnum.cancle.getStatus()));
            PageResult<FlowApplyDO> pageResult = flowApplyAO.queryFlowApply(query, null);
            if (pageResult.getTotalCount() > 1) {
                logger.error("当前用户存在多个活动的申请[userId={}, partnerId={}]", userId, userDO.getPartnerId());
                result.setMsg("当前用户存在多个活动的申请");
                return result;
            } else if (pageResult.getTotalCount() == 1) { // 更新操作
                FlowApplyDO applyDO = pageResult.getResult().get(0);
                if (applyDO.getState() == FlowStateEnum.init.getStatus()) {
                    result.setMsg("当前用户已申请");
                    logger.error("当前用户已申请userId={}", userId);
                } else {
                    ProviderCertificatePO providerCertificatePO = this.assemblyPO(userDO, partnerDO);
                    applyDO.setContentObject(providerCertificatePO);
                    flowApplyAO.reApplyFlow(applyDO, null);
                }
            } else { // 插入操作
                ProviderCertificatePO providerCertificatePO = this.assemblyPO(userDO, partnerDO);
                FlowApplyDO flowApplyDO = new FlowApplyDO();
                flowApplyDO.setContentObject(providerCertificatePO);
                flowApplyDO.setAttachBizId(partnerDO.getId());
                flowApplyDO.setAttachBizType(AttachBizTypeEnum.partner.name());
                flowApplyDO.setFlowBizType(FlowBizTypeEnun.providerCertificate.name());
                flowApplyAO.createApply(flowApplyDO);
            }
            //userDO.setIsVerify(1);
            userManager.updateByPrimaryKeySelective(userDO);
        } catch (Exception e) {
            logger.error("userId=" + userId, e);
            result.setMsg("系统异常");
        }
        return result;
    }


    private ProviderCertificatePO assemblyPO(UserDO userDO, PartnerDO partnerDO) {
        ProviderCertificatePO providerCertificate = new ProviderCertificatePO();
        providerCertificate.setCorpName(partnerDO.getCorpName());
        providerCertificate.setCertificateCode(partnerDO.getCertificateCode());
        providerCertificate.setContactsName(partnerDO.getContactsName());
        providerCertificate.setContactsPhone(partnerDO.getContactsPhone());
        providerCertificate.setUserId(userDO.getId());
        providerCertificate.setPartnerId(userDO.getPartnerId());
        return providerCertificate;
    }


    private PersonCertificatePO assemblyPO(PersonCertificateModel person, UserDO userDO) {
        PersonCertificatePO personCertificate = new PersonCertificatePO();
        personCertificate.setCertImgs(person.getCertImgs());
        personCertificate.setCertNo(person.getCertNo());
        personCertificate.setUserId(person.getUserId());
        personCertificate.setRealName(person.getRealName());
        personCertificate.setVisitingCardImgs(person.getVisitingCardImgs());

        personCertificate.setLoginName(userDO.getLoginName());
        if (null != userDO.getPartnerId() && userDO.getPartnerId() > 0) {
            PartnerDO partnerDO = partnerManager.selectByPrimaryKey(userDO.getPartnerId());
            if (null != partnerDO) {
                personCertificate.setCorpName(partnerDO.getCorpName());
            }
        }

        return personCertificate;

    }


    private EnterpriseCertificatePO assemblyPO(EnterpriseCertificateModel enterprise, UserDO userDO) {
        EnterpriseCertificatePO enterpriseCertificate = new EnterpriseCertificatePO();
        enterpriseCertificate.setUserId(enterprise.getUserId());
        enterpriseCertificate.setCertificateCode(enterprise.getCertificateCode());
        try {
            enterpriseCertificate.setCity(null == enterprise.getCity() ?  null  : Integer.parseInt(enterprise.getCity()));
            enterpriseCertificate.setProvince(null == enterprise.getProvince() ? null : Integer.parseInt(enterprise.getProvince()));
            if(null == enterpriseCertificate.getProvince() || enterpriseCertificate.getProvince() == 0){
                if(null != enterpriseCertificate.getCity()){
                    City city = CityData.getCityById(enterpriseCertificate.getCity());
                    if(null != city){
                        enterpriseCertificate.setProvince(city.getProID());
                    }
                }
            }
        }catch (Exception e){
            logger.error("数据转换异常, city={}, province={}", enterprise.getCity(),enterprise.getProvince());
        }
        enterpriseCertificate.setCityName(enterprise.getCityName());
        enterpriseCertificate.setCorpName(enterprise.getCorpName());
        enterpriseCertificate.setStoreImgs(enterprise.getStoreImgs());
        enterpriseCertificate.setCredentialsImgs(enterprise.getCredentialsImgs());
        enterpriseCertificate.setLegalImgs(enterprise.getLegalImgs());
        enterpriseCertificate.setContactsName(userDO.getRealName());
        enterpriseCertificate.setContactsPhone(userDO.getLoginName());
        if (null != userDO.getPartnerId() && userDO.getPartnerId() > 0) {
            PartnerDO partnerDO = partnerManager.selectByPrimaryKey(userDO.getPartnerId());
            if (null != partnerDO) {
                enterpriseCertificate.setCorpName(partnerDO.getCorpName());
            }
        }

        return enterpriseCertificate;

    }

}
